package fr.afcepf.ai89.esharing.data;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import fr.afcepf.ai89.esharing.entity.CategorieAem;
import fr.afcepf.ai89.esharing.entity.Marque;
import fr.afcepf.ai89.esharing.entity.TypeAem;

@Stateless
public class DAOTypeAem implements IDAOTypeAem {

	@PersistenceContext(unitName = "ESharingPhase22")
	EntityManager em;

	@Override
	public TypeAem getTypeAem(int idType) {

		Query hql = em.createQuery("SELECT t from TypeAem t WHERE t.idTypeAem = :param");
		
		hql.setParameter("param", idType);
		TypeAem type = (TypeAem)hql.getSingleResult();

		return type;

	}

	@Override
	public List<TypeAem> getTypesAems() {

		Query hql = em.createQuery("SELECT t from TypeAem t");

		List<TypeAem> types = (List<TypeAem>)hql.getResultList();

		return types;

	}

	@Override
	public List<TypeAem> getTypesAems(Marque marque) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<TypeAem> getTypesAems(CategorieAem cat) {
		
		Query hql = em.createQuery("SELECT t from TypeAem t WHERE t.categorieAem.idCategorieAem = :param");
		
		hql.setParameter("param", cat.getIdCategorieAem());
		List<TypeAem> types = (List<TypeAem>)hql.getResultList();

		return types;

	}

	@Override
	public int addType(TypeAem type) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int majType(TypeAem type) {
		// TODO Auto-generated method stub
		return 0;
	}

}
